
<!DOCTYPE html>
<html><head>
   <meta charset="utf-8">
   <title>修改商品</title>

   <meta name="description" content="Dashboard">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <!--Basic Styles-->
   <link href="__admin__/style/bootstrap.css" rel="stylesheet">
   <link href="__admin__/style/font-awesome.css" rel="stylesheet">
   <link href="__admin__/style/weather-icons.css" rel="stylesheet">

   <!--Beyond styles-->
   <link id="beyond-link" href="__admin__/style/beyond.css" rel="stylesheet" type="text/css">
   <link href="__admin__/style/demo.css" rel="stylesheet">
   <link href="__admin__/style/typicons.css" rel="stylesheet">
   <link href="__admin__/style/animate.css" rel="stylesheet">

   <!-- 引入ueditor -->
   <script type="text/javascript" charset="utf-8" src="__plus__/ueditor/ueditor.config.js"></script>
   <script type="text/javascript" charset="utf-8" src="__plus__/ueditor/ueditor.all.min.js"> </script>
   <script type="text/javascript" charset="utf-8" src="__plus__/ueditor/lang/zh-cn/zh-cn.js"></script>

<style type="text/css">
    .price{
        width: 150px;
        margin-left: 10px;
        display: inline-block;
    }
    .abtn{
        padding-right: 10px;
    }
    </style>

</head>
<body>
    <!-- 头部 -->
    {include file="common/top"}

    <!-- /头部 -->

    <div class="main-container container-fluid">
      <div class="page-container">
        <!-- Page Sidebar -->
        {include file="common/left"}
        <!-- /Page Sidebar -->
        <!-- Page Content -->
        <div class="page-content">
            <!-- Page Breadcrumb -->
            <div class="page-breadcrumbs">
                <ul class="breadcrumb">
                    <li>
                        <a href="{:url('index/index')}">系统</a>
                    </li>
                    <li>
                        <a href="{:url('goods/lst')}">商品列表</a>
                    </li>
                    <li class="active">商品编辑</li>
                </ul>
            </div>
            <!-- /Page Breadcrumb -->

            <!-- Page Body -->
            <div class="page-body">

                <div class="row">
                    <div class="col-lg-12 col-sm-12 col-xs-12">
                        <div class="widget">
                            <div id="horizontal-form">
                                <form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
                                    <input type="hidden" name="id" value="{$GoodsRes.id}">
                                    <div class="widget-body">
                                        <div class="widget-main ">
                                            <div class="tabbable">
                                                <ul class="nav nav-tabs tabs-flat" id="myTab11">
                                                    <li class="active">
                                                        <a data-toggle="tab" href="#baseInfo" >
                                                           基本信息
                                                       </a>
                                                   </li>

                                                   <li class="">
                                                    <a data-toggle="tab" href="#description" >
                                                        描述信息
                                                    </a>
                                                </li>
                                                <li class="">
                                                    <a data-toggle="tab" href="#memPrice" >
                                                        会员价格
                                                    </a>
                                                </li>

                                                <li class="">
                                                    <a data-toggle="tab" href="#goodsAttr" >
                                                       商品属性
                                                   </a>
                                               </li>

                                               <li class="">
                                                <a data-toggle="tab" href="#goodsPhoto" >
                                                    商品相册
                                                </a>
                                            </li>


                                        </ul>
                                        <div class="tab-content tabs-flat">
                                            <!-- 基本信息 -->
                                            <div id="baseInfo" class="tab-pane active">
                                                <div class="form-group">
                                                    <label for="username" class="col-sm-2 control-label no-padding-right">商品名称</label>
                                                    <div class="col-sm-6">
                                                        <input class="form-control"  required="" name="goods_name"  type="text" value="{$GoodsRes.goods_name}">
                                                    </div>
                                                </div>


                                                <div class="form-group">
                                                    <label for="username" class="col-sm-2 control-label no-padding-right">商品推荐位</label>
                                                    <div class="col-sm-6">
                                                        <div class="checkbox">
                                                        {volist name="GoodsRecposRes" id="vo"}
                                                        <label>
                                                            <?php
                                                            if(in_array($vo['id'], $myGoodsRecposRes)){
                                                            $checked='checked="checked"';
                                                        }else{
                                                        $checked='';
                                                    }
                                                    ?>
                                                            <input type="checkbox" <?php echo $checked;?> class="colored-blue" name="recpos[]" value="{$vo.id}">
                                                            <span class="text">{$vo.rec_name}</span>
                                                        </label>
                                                        {/volist}
                                                    </div>
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label for="username" class="col-sm-2 control-label no-padding-right">所属栏目</label>
                                                    <div class="col-sm-6">
                                                        <select name="category_id">
                                                            <option value="0">请选择</option>
                                                            {volist name="CateGoryRes" id="vo"}
                                                            <option {if condition="$vo['id']==$GoodsRes['category_id']" }selected="selected"{/if} value="{$vo.id}">
                                                                <?php echo str_repeat('-', $vo['level']*8)?>{$vo.cate_name}</option>
                                                            {/volist}
                                                        </select>
                                                    </div>
                                                </div>


                                                <div class="form-group">
                                                    <label for="username" class="col-sm-2 control-label no-padding-right">所属品牌</label>
                                                    <div class="col-sm-6">
                                                        <select name="brand_id">
                                                            <option value="0">请选择</option>
                                                            {volist name="BrandRes" id="vo"}
                                                            <option {if condition="$vo['id']==$GoodsRes['brand_id']" }selected="selected"{/if} value="{$vo.id}">{$vo.brand_name}</option>
                                                            {/volist}
                                                        </select>
                                                    </div>
                                                </div>


                                                <div class="form-group">
                                                    <label for="username" class="col-sm-2 control-label no-padding-right">上架</label>
                                                    <div class="col-sm-6">
                                                        <div class="radio">
                                                            <label>
                                                                <input name="on_sale" type="radio"  value="1" {if condition="$GoodsRes['on_sale']==1"}checked="checked"{/if} class="colored-blue">
                                                                <span class="text">是</span>
                                                            </label>
                                                            <label>
                                                                <input name="on_sale"  value="0" type="radio"  {if condition="$GoodsRes['on_sale']==0"}checked="checked"{/if}   class="colored-blue">
                                                                <span class="text">否</span>
                                                            </label>
                                                        </div>

                                                    </div>

                                                </div>


                                                <div class="form-group">
                                                    <label for="username" class="col-sm-2 control-label no-padding-right">商品主图</label>
                                                    <div class="col-sm-6">
                                                        <input   name="or_thumb"   type="file">
                                                        {if condition="$GoodsRes['or_thumb'] neq ''"}
                                                        <img src="__uploads__/{$GoodsRes.or_thumb}" height="30px">
                                                        {else/}
                                                        暂无缩略图
                                                        {/if}
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label for="username" class="col-sm-2 control-label no-padding-right">市场价</label>
                                                    <div class="col-sm-6">
                                                        <input class="form-control"  required="" name="market_price"  type="text" value="{$GoodsRes.market_price}">
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label for="username" class="col-sm-2 control-label no-padding-right">本店价</label>
                                                    <div class="col-sm-6">
                                                        <input class="form-control"  required="" name="shop_price"  type="text" value="{$GoodsRes.shop_price}">
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right">重量</label>
                                                <div class="col-sm-6">
                                                    <input class="form-control" style="width:300px; display:inline-block;" placeholder="" name="goods_weight" required="" type="text" value="{$GoodsRes.goods_weight}">
                                                    <select name="weight_unit">
                                                        <option {if condition="$GoodsRes['weight_unit'] eq 'kg'"} selected="selected" {/if} value="kg">kg</option>
                                                        <option {if condition="$GoodsRes['weight_unit'] eq 'g' "} selected="selected" {/if}  value="g">g</option>
                                                    </select>
                                                </div>
                                                
                                            </div>
                                            </div>


                                            <!-- 描述信息 -->
                                            <div id="description" class="tab-pane">
                                                <div class="form-group">
                                                    <label for="username" class="col-sm-2 control-label no-padding-right">商品描述</label>
                                                    <div class="col-sm-6">
                                                        <textarea  id="content"  name="goods_des">{$GoodsRes.goods_des}</textarea>
                                                    </div>
                                                </div>
                                            </div>
                                            

                                            <!-- 会员价格 -->
                                            <div id="memPrice" class="tab-pane ">
                                                {volist name="MemberLevelRes" id="vo"}
                                                <!-- <?php 
                                                $price='';
                                                foreach($MemberPriceRes as $k=>$v){
                                                     if($vo['id']==$v['mlevel_id']){
                                                            $price=$v['mprice'];
                                                            break;
                                                        }
                                                    }
                                                ?>  value="{$price}"-->
                                                <div class="form-group">
                                                    <label for="username" class="col-sm-2 control-label no-padding-right">{$vo.level_name}</label>
                                                    <div class="col-sm-6">
                                                        <input class="form-control"   name="mp[{$vo.id}]" value="<?php if(isset($MemberPriceRes[$vo['id']]['mprice'])){echo $MemberPriceRes[$vo['id']]['mprice']; }else{echo '';}?>"  type="text">
                                                    </div>
                                                </div>
                                                {/volist}
                                            </div>

                                            
                                            <!-- 商品属性 -->
                                             <div id="goodsAttr" class="tab-pane activ">
                                                <div class="form-group">
                                                    <label for="username" class="col-sm-2 control-label no-padding-right">所属类型</label>
                                                    <div class="col-sm-6">
                                                        <select name="type_id" {if condition="$GoodsRes['type_id'] neq 0"} disabled="disabled" {/if}>
                                                            <option value="0">请选择</option>
                                                            {volist name="TypeRes" id="vo"}
                                                            <option {if condition="$vo['id'] eq $GoodsRes['type_id']"}selected="selected"{/if} value="{$vo.id}">{$vo.type_name}
                                                            </option>
                                                            {/volist}
                                                        </select>
                                                    </div>

                                                </div>

                                                <div id="attr_list">
                                                    <!--  属性展示 -->
                                                    <?php foreach($AttrRes as $k=>$v):?>
                                                    <?php if($v['attr_type']==1):
                                                    $arr=explode(',',$v['attr_values']);
                                                    ?>
                                                    <?php foreach($GoodsAttrRes[$v['id']] as $k0=>$v0):?>
                                                    <!-- 单选属性 -->
                                                    <div gaid="{$v0['id']}" class="form-group">
                                                        <label class="col-sm-2 control-label no-padding-right">{$v['attr_name']}
                                                        </label>
                                                        <div class="col-sm-6">
                                                        <a class="abtn" onclick="addrow(this);" href="#"><?php if($k0==0){echo "[+]";}else{echo "[-]";}?></a>
                                                        <select name="old_goods_attr[{$v['id']}][]">
                                                            <option value="">请选择</option>
                                                            <?php foreach($arr as $k1=>$v1):?>
                                                            <option <?php if($v0['attr_value']==$v1){echo "selected='selected'";}?> value="<?php echo $v1;?>"><?php echo $v1;?></option>
                                                            <?php endforeach;?>
                                                        </select>
                                                         <input type="hidden" name="old_goods_attrID[]" value="{$v0['id']}">
                                                        <input class="form-control price" placeholder="价格" name="old_attr_price[]" type="text" value="<?php echo $v0['attr_price'];?>"></div></div>

                                                        <?php endforeach;?>
                                                        <?php else:?>
                                                        <?php if($v['attr_values']):
                                                        $arr=explode(',',$v['attr_values']);
                                                        ?>
                                                        <!-- 唯一属性 -->
                                                        <div class="form-group">
                                                            <label class="col-sm-2 control-label no-padding-right">{$v['attr_name']}</label>
                                                            <div class="col-sm-6">
                                                            <select name="old_goods_attr[{$v['id']}]">
                                                                <option value="">请选择</option>
                                                                <?php foreach($arr as $k1=>$v1):?>
                                                                <option <?php if($GoodsAttrRes[$v['id']][0]['attr_value']==$v1){echo "selected='selected'";}?> value="<?php echo $v1;?>"><?php echo $v1;?></option>
                                                                <?php endforeach;?>
                                                            </select>
                                                             <input type="hidden" name="old_goods_attrID2[]" value="{$GoodsAttrRes[$v['id']][0]['id']}">
                                                            </div>
                                                        </div>

                                                        <?php else:?>
                                                        <div class="form-group">
                                                            <label class="col-sm-2 control-label no-padding-right">{$v['attr_name']}</label>
                                                            <div class="col-sm-6">
                                                                 <input type="hidden" name="old_goods_attrID2[]" value="{$GoodsAttrRes[$v['id']][0]['id']}">
                                                            <input class="form-control price" type="text" name="old_goods_attr[{$v['id']}]" value="{$GoodsAttrRes[$v['id']][0]['attr_value']}">
                                                            </div>
                                                        </div>
                                                       <?php endif;?>
                                                       <?php endif;?>
                                                       <?php endforeach;?>
                                                   </div>
                                            </div>


                                            <!-- 商品相册 -->
                                            <div id="goodsPhoto" class="tab-pane ">
                                                {volist name="gphotoRes" id="vo"}
                                                <div id="{$vo.id}" class="form-group">
                                                    <div  class="col-sm-6">
                                                        <a href="#" class="col-sm-2 control-label no-padding-right" onclick="delrow(this);">[-]</a>
                                                        <img src="__uploads__/{$vo.sm_photo}" height="50">
                                                    </div>
                                                </div>
                                                {/volist}

                                                <div class="form-group">
                                                    <div class="col-sm-6">
                                                        <a href="#" class="col-sm-2 control-label no-padding-right" onclick="addrow(this);">[+]</a>
                                                        <input   name="goods_photo[]"   type="file">
                                                    </div>
                                                </div>
                                            </div> 
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-10">
                                            <button type="submit" class="btn btn-default">保存</button>
                                        </div>
                                    </div>



                                </div>
                            </div>




                        </form>
                    </div>
                </div>
            </div>
        </div>


    </div>
    <!-- /Page Body -->
</div>
<!-- /Page Content -->
</div>  
</div>

<!--Basic Scripts-->
<script src="__admin__/style/jquery_002.js"></script>
<script src="__admin__/style/bootstrap.js"></script>
<script src="__admin__/style/jquery.js"></script>
<!--Beyond Scripts-->
<script src="__admin__/style/beyond.js"></script>

<script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('content',{initialFrameWidth:1200,initialFrameHeight:600});
</script>

<script type="text/javascript">
    $("select[name=type_id]").change(function(){
        var type_id=$(this).val();
        // alert(type_id);
        $.ajax({
            type:"POST",
            url:"{:url('Attr/ajaxGetAttr')}",
            data:{type_id:type_id},
            dataType:"json",
            success:function(data){
                // console.log(data);
                var html="";
                data=JSON.parse(data); //解析json
                $(data).each(function(k,v){
                    if(v.attr_type == 1){
                        // 单选处理
                        html+="<div class='form-group'>";
                        html+="<label class='col-sm-2 control-label no-padding-right'>"+v.attr_name+"</label>";
                        var attrValuesArr=v.attr_values.split(",");
                        html+="<div class='col-sm-6'><a class='abtn' onclick='addrow(this);' href='#'>[+]</a>";
                        html+="<select name='goods_attr["+v.id+"][]'>";
                        html+="<option value=''>请选择</option>";
                        for(var i=0; i<attrValuesArr.length; i++){
                            html+="<option value='"+attrValuesArr[i]+"'>"+attrValuesArr[i]+"</option>";
                        }
                        html+="</select>";
                        html+="<input class='form-control price' placeholder='价格' name='attr_price[]' type='text'>";
                        html+="</div></div>";

                    }else{
                        // 唯一处理
                        if(v.attr_values){
                            html+="<div class='form-group'>";
                            html+="<label class='col-sm-2 control-label no-padding-right'>"+v.attr_name+"</label>";
                            var attrValuesArr=v.attr_values.split(",");
                            html+="<div class='col-sm-6'>";
                            html+="<select name='goods_attr["+v.id+"]'>";
                            html+="<option value=''>请选择</option>";
                            for(var i=0; i<attrValuesArr.length; i++){
                                html+="<option value='"+attrValuesArr[i]+"'>"+attrValuesArr[i]+"</option>";
                            }
                            html+="</select>";
                            html+="</div></div>";
                        }else{
                            html+="<div class='form-group'>";
                            html+="<label class='col-sm-2 control-label no-padding-right'>"+v.attr_name+"</label>";
                            var attrValuesArr=v.attr_values.split(",");
                            html+="<div class='col-sm-6'>";
                            html+="<input class='form-control price' type='text' name='goods_attr["+v.id+"]'>";
                            html+="</div></div>";
                        }
                    }
                });
                $("#attr_list").html(html);
            }
        });
    });


    function addrow(o){
        var div=$(o).parent().parent();
        if($(o).html() == '[+]'){
            var newdiv=div.clone();    
            newdiv.find('a').html('[-]');
            // 修改old_attr_price[]为attr_price[]
            newdiv.find(':text').attr('name','attr_price[]');
            // 修改old_goods_attr[][]为goods_attr[][]
            var sel=newdiv.find('select');
            var oldname=sel.attr('name');
            var newname=oldname.replace('old_','');
            sel.attr('name',newname);
            div.after(newdiv);
            
        }else{
            if(confirm('确定删除该属性吗？')){
                var div=$(o).parent().parent();
                var gaid=div.attr('gaid');
                $.ajax({
                    type:"post",
                    url:"{:url('goodsAttr/ajaxdelga')}",
                    data:{gaid:gaid},
                    success:function($data){
                     if($data==1){
                        div.remove();
                    }else{
                        alert('删除失败');
                    }

                    }

                });

            }
        }
    }

    function delrow(o){
        if(confirm('确定删除该图片吗?')){
            var div=$(o).parent().parent();
            var id=div.attr('id');
            $.ajax({
                type:"post",
                url:"{:url('Goods/ajaxdelpic')}",
                data:{id:id},
                success:function($data){
                    if($data==1){
                        div.remove();
                    }else{
                        alert('删除失败');
                    }
                   
                }
            });
            


        }
        

    }
</script>


</body></html>